﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="World.aspx.cs" Inherits="World.World" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="ContinentsListBox" runat="server"
            DataSourceID="ContinentsDataSource" DataTextField="Name" 
            DataValueField="ContinentID" AutoPostBack="True" 
            onselectedindexchanged="ContinentsListBox_SelectedIndexChanged"></asp:ListBox>
        <asp:EntityDataSource ID="ContinentsDataSource" runat="server" OrderBy="it.Name"
            ConnectionString="name=WorldEntities1" DefaultContainerName="WorldEntities1" 
            EnableFlattening="False" EntitySetName="Continents" EnableDelete="True" 
            EnableInsert="True" EnableUpdate="True">
        </asp:EntityDataSource>
        <asp:GridView ID="CountriesGridView" runat="server" AutoGenerateColumns="False" ShowFooter="True"
            DataKeyNames="CountryID" DataSourceID="CountriesDataScource" Visible="False"
            onselectedindexchanged="CountriesGridView_SelectedIndexChanged" 
            AllowPaging="True" onprerender="CountriesGridView_PreRender" 
            oninit="CountriesGridView_Init" onload="CountriesGridView_Load" 
            onrowupdating="CountriesGridView_RowUpdating">
            <Columns>
                
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                    ShowSelectButton="True" />
                <asp:BoundField DataField="CountryID" HeaderText="CountryID" ReadOnly="True"
                    SortExpression="CountryID" />
                <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <asp:Label runat="server" Text= '<%# Eval("Name") %>' ></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" id="EditNameTextBox" Text='<%#Bind("Name") %>'></asp:TextBox>
                    </EditItemTemplate>
                  
                    <FooterTemplate>
                        <asp:TextBox runat="server" id="CountryNameTB"></asp:TextBox>
                    </FooterTemplate>
                </asp:TemplateField>
                 <asp:TemplateField HeaderText="Language">
                    <ItemTemplate>
                        <asp:Label runat="server" Text= '<%# Eval("Language") %>' ></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="EditLanguageTextBox" Text='<%# Bind("Language") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox runat="server" id="CountryLanguageTB"></asp:TextBox>
                    </FooterTemplate>
                </asp:TemplateField>
                 <asp:TemplateField HeaderText="Population">
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text= '<%# Eval("Population") %>' ></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="EditPopulationTextBox" Text='<%# Bind("Population") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox runat="server" id="CountryPopulationTB"></asp:TextBox>
                    </FooterTemplate>
                </asp:TemplateField>
         
                <asp:BoundField DataField="ContinentID" HeaderText="ContinentID" 
                    SortExpression="ContinentID" />

                <asp:TemplateField HeaderText = "Flag">
                    <ItemTemplate>
                        <asp:Image id="ImageFlag" runat="server" ImageUrl='<%#"~/ShowImage.ashx?id="+ Eval("CountryID") %>'/>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:FileUpload ID="FileUploadFlag" runat="server" />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:FileUpload ID="FileUploadFlagFooter" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:EntityDataSource ID="CountriesDataScource" runat="server" 
            ConnectionString="name=WorldEntities1" DefaultContainerName="WorldEntities1" 
            EnableFlattening="False" EntitySetName="Countries" EnableDelete="True" 
            EnableInsert="True" EnableUpdate="True">
        </asp:EntityDataSource>
       
        <asp:ListView runat="server" ID="TownsListView" DataKeyNames="TownID" 
            DataSourceID="TownsDataSource" InsertItemPosition="LastItem" 
            Visible="False" oniteminserted="TownsListView_ItemInserted" 
            onitemdatabound="TownsListView_ItemDataBound" 
            onitemcreated="TownsListView_ItemCreated">
            <AlternatingItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                            Text="Delete" />
                        <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="TownIDLabel" runat="server" Text='<%# Eval("TownID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
                    </td>
                    <td>
                        <asp:Label ID="PopulationLabel" runat="server" 
                            Text='<%# Eval("Population") %>' />
                    </td>
                    <td>
                        <asp:Label ID="CountryIDLabel" runat="server" Text='<%# Eval("CountryID") %>' />
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <EditItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                            Text="Update" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                            Text="Cancel" />
                    </td>
                    <td>
                        <asp:Label ID="TownIDLabel1" runat="server" Text='<%# Eval("TownID") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="PopulationTextBox" runat="server" 
                            Text='<%# Bind("Population") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="CountryIDTextBox" runat="server" 
                            Text='<%# Bind("CountryID") %>' />
                    </td>
                </tr>
            </EditItemTemplate>
            <EmptyDataTemplate>
                <table runat="server" style="">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <InsertItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                            Text="Insert" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                            Text="Clear" />
                    </td>
                    <td>
                        <asp:Label ID="TownIDTextBox" runat="server" Text='<%# Bind("TownID") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="PopulationTextBox" runat="server" 
                            Text='<%# Bind("Population") %>' />
                    </td>
                    <td>
                        <asp:Label ID="CountryIDTextBox" runat="server" 
                            Text='<%# Bind("CountryID") %>' ReadOnly="true" />
                    </td>
                </tr>
            </InsertItemTemplate>
            <ItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                            Text="Delete" />
                        <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="TownIDLabel" runat="server" Text='<%# Eval("TownID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
                    </td>
                    <td>
                        <asp:Label ID="PopulationLabel" runat="server" 
                            Text='<%# Eval("Population") %>' />
                    </td>
                    <td>
                        <asp:Label ID="CountryIDLabel" runat="server" Text='<%# Eval("CountryID") %>' />
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <table runat="server">
                    <tr runat="server">
                        <td runat="server">
                            <table ID="itemPlaceholderContainer" runat="server" border="0" style="">
                                <tr runat="server" style="">
                                    <th runat="server">
                                    </th>
                                    <th runat="server">
                                        TownID</th>
                                    <th runat="server">
                                        Name</th>
                                    <th runat="server">
                                        Population</th>
                                    <th runat="server">
                                        CountryID</th>
                                </tr>
                                <tr ID="itemPlaceholder" runat="server">
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr runat="server">
                        <td runat="server" style="">
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                            Text="Delete" />
                        <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                    </td>
                    <td>
                        <asp:Label ID="TownIDLabel" runat="server" Text='<%# Eval("TownID") %>' />
                    </td>
                    <td>
                        <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
                    </td>
                    <td>
                        <asp:Label ID="PopulationLabel" runat="server" 
                            Text='<%# Eval("Population") %>' />
                    </td>
                    <td>
                        <asp:Label ID="CountryIDLabel" runat="server" Text='<%# Eval("CountryID") %>' />
                    </td>
                </tr>
            </SelectedItemTemplate>
        </asp:ListView>
        <asp:EntityDataSource ID="TownsDataSource" runat="server" 
            ConnectionString="name=WorldEntities1" DefaultContainerName="WorldEntities1" 
            EnableDelete="True" EnableFlattening="False" EnableInsert="True" 
            EnableUpdate="True" EntitySetName="Towns">
        </asp:EntityDataSource>
    </div>
    </form>
</body>
</html>
